/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.geomagnetic_sensor.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.geomagnetic_sensor.entity.GeomagneticSensor;
import com.thinkgem.jeesite.modules.geomagnetic_sensor.service.GeomagneticSensorService;

/**
 * 地磁传感器信息Controller
 * @author xlp
 * @version 2019-04-12
 */
@Controller
@RequestMapping(value = "${adminPath}/geomagnetic_sensor/geomagneticSensor")
public class GeomagneticSensorController extends BaseController {

	@Autowired
	private GeomagneticSensorService geomagneticSensorService;
	
	@ModelAttribute
	public GeomagneticSensor get(@RequestParam(required=false) String id) {
		GeomagneticSensor entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = geomagneticSensorService.get(id);
		}
		if (entity == null){
			entity = new GeomagneticSensor();
		}
		return entity;
	}
	
	@RequiresPermissions("geomagnetic_sensor:geomagneticSensor:view")
	@RequestMapping(value = {"list", ""})
	public String list(GeomagneticSensor geomagneticSensor, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GeomagneticSensor> page = geomagneticSensorService.findPage(new Page<GeomagneticSensor>(request, response), geomagneticSensor); 
		model.addAttribute("page", page);
		return "modules/geomagnetic_sensor/geomagneticSensorList";
	}

	@RequiresPermissions("geomagnetic_sensor:geomagneticSensor:view")
	@RequestMapping(value = "form")
	public String form(GeomagneticSensor geomagneticSensor, Model model) {
		model.addAttribute("geomagneticSensor", geomagneticSensor);
		return "modules/geomagnetic_sensor/geomagneticSensorForm";
	}

	@RequiresPermissions("geomagnetic_sensor:geomagneticSensor:edit")
	@RequestMapping(value = "save")
	public String save(GeomagneticSensor geomagneticSensor, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, geomagneticSensor)){
			return form(geomagneticSensor, model);
		}
		geomagneticSensorService.save(geomagneticSensor);
		addMessage(redirectAttributes, "保存地磁传感器信息成功");
		return "redirect:"+Global.getAdminPath()+"/geomagnetic_sensor/geomagneticSensor/?repage";
	}
	
	@RequiresPermissions("geomagnetic_sensor:geomagneticSensor:edit")
	@RequestMapping(value = "delete")
	public String delete(GeomagneticSensor geomagneticSensor, RedirectAttributes redirectAttributes) {
		geomagneticSensorService.delete(geomagneticSensor);
		addMessage(redirectAttributes, "删除地磁传感器信息成功");
		return "redirect:"+Global.getAdminPath()+"/geomagnetic_sensor/geomagneticSensor/?repage";
	}

}